home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol151 / tabs19.asm < prev    next >
Encoding:
Assembly Source File  |  1986-12-16  |  10.3 KB  |  697 lines

  1. Page82,132
  2. TitleTABS - Align ASCII File
  3.  
  4. Comment| Version 1.9, June 5, 1985
  5.  
  6. TABS Command
  7. -----------------
  8.  
  9. Purpose:   Replace blanks with TAB character(s); or expand TABs.
  10.  
  11. Format [d:[input.ext]] [d:[output.ext]] [/D]
  12.  
  13. RemarkIf TABS
  14. appear they will
  15. not be expanded.
  16.  
  17. The /D file,
  18.  
  19. The masee MAXREC equate.
  20. Defact9,17,25,...
  21.  
  22. WrittIBM PC using DOS 2.
  23. For public domain use.
  24.  
  25. Notes1.6 includes a correction for the use of wildcards
  26. to nainput file if only
  27. a drivewas supplied for the output file name.
  28.  
  29. Version1.7 fixes a problem regarding the EOF character. It
  30. now considers the EOF as the end of a file and will no longer
  31. copy dathat point. Also, if wildcards are used, all
  32. matching files are processed.
  33.  
  34. Version1.8 cleans up the messages displayed.
  35.  
  36. Version 1.9 requires the ouput file on a different drive,
  37. or in a different path.
  38. -|
  39.  
  40. CSePublic Para 'CODE'
  41. AssumeCS:Cseg,DS:Cseg,ES:CSeg
  42. Org100h
  43.  
  44. Far
  45. ;Save sto insure return
  46.  
  47. Ca;Check for DOS 2
  48.  
  49. C;Get maximum I/O buffers
  50.  
  51. Cal;Get file names
  52.  
  53. Again:
  54. Ca;Open input
  55.  
  56. Cal; and output
  57.  
  58. Ca;Display "cooking" message
  59.  
  60. Ca;Generate tabs
  61.  
  62. C;Empty the output buffer
  63.  
  64. C;Close files
  65.  
  66. ;Get next matching file
  67. OrAL,AL
  68. JzAgain
  69. ;All done
  70. JmpShort Exit
  71.  
  72. ESproper return
  73. Ca;Print any message
  74.  
  75. MovAL,to 1
  76. AH,4Ch
  77. Int21to DOS
  78. Page
  79. ;
  80. work areas
  81.  
  82. 0;I/O buffer size
  83. M51sector
  84. M255;Longest logical record
  85.  
  86. S_3quote
  87. D_3quote
  88. TabEqu9
  89. LFEqu10
  90. CREqu13
  91. EOFEqu1Ah
  92. St255
  93.  
  94. Rec;Current record
  95. SwDbof blanks skipped
  96. QswDb0;Quote switch
  97. ;Non-zero for detab function
  98. S0;SP at entry
  99.  
  100. Msg1DbCR,LF,'Input failed to open, '
  101. Inp;Drive:path\name.ext
  102. I0;Input file handle
  103. IlenDw0;Input block length
  104. IptrDchar
  105. 0;Seg offset
  106.  
  107. Msg2DbCR,LF,'Output failed to open, '
  108. 76 Dup (0),0,CR,LF,Stopper
  109. Ofile handle
  110. OlenDw0;Bytes in output buffer
  111. OptrDchar
  112. O0;Seg offset
  113.  
  114. 8 Dup (' ')
  115. FOffs;Addr of file name part
  116. Offse;Spot for output file name
  117. DTADb48;DOS data transfer area
  118. Page
  119. ;
  120. ;Messages
  121.  
  122. V'TABS - Version 1.9 - V.Buerg',CR,LF,CR,LF
  123. Db'Usage:  TABS  infile  outfile  [/D]',CR,LF
  124. Db' o  infile and outfile may include drive and path names',CR,LF
  125. Db' o  use ending /D to expand tabs to spaces.',CR,LF
  126. Db' o  June 5, 1985; public domain.',Stopper
  127. SorryDbCR,LF,'Wrong PC DOS Version',Stopper
  128. Msg3fDbCR,LF,'Read error',Stopper
  129. Msg40DbCR,LF,'Write error or Disk full.',Stopper
  130. Msg4aDbCR,LF,'Not enough memory',Stopper
  131. Msg4eDbCR,LF,'No matching file(s) found',Stopper
  132. I'DE-'
  133. C'TABS:',9,Stopper
  134. MarkDb9,'-> ',Stopper
  135. NCR,LF,Stopper
  136.  
  137. Code2Db'File not found ',Stopper
  138. Code3Db'Path not found ',Stopper
  139. Code4Db'Too many files ',Stopper
  140. Code5Db'Access denied  ',Stopper
  141. Page
  142. ;
  143. blanks with tabs
  144.  
  145. GeNear
  146. LGetRec;Get a record, length in CX
  147. ;Outputcolumn
  148. ;No blanks yet
  149. M;No quotes yet
  150. OrCX,CX;Any data in record?
  151. JzNull; no, just CR-LF
  152.  
  153. SI,Of;Look for blanks and
  154. Wlo; replace strings of blanks
  155. IncBX; with tab characters
  156. CmpAL;Don't count blanks
  157. JneChkor double
  158. ; quoted strings
  159. JmpChk2
  160.  
  161. ATABs for any
  162. JneChk3; blanks skipped before
  163. ; a quote
  164. Sw,0;Must re-insert
  165. JeCheck; any blanks skipped
  166. for a TAB
  167.  
  168. Detab,record as-is
  169. ; if de-tabbing
  170. C;Tis a blank?
  171. ; no, see if eof
  172. quotes?
  173. JnzCheck
  174. IncSw
  175. Te;Ready for a tab?
  176. ; no, keep going
  177. M; yes, send one
  178. JmpCopy
  179.  
  180. CAL,EOfile?
  181. JeDone; yes, all done
  182. CmpDetab,0
  183. JneCopy
  184. non-blank is
  185. JnzCopTAB
  186. CmpSw,blanks
  187. JeCopy; before it
  188. MovDX,BX
  189. DecDL
  190. Tnon-blank is not
  191. J; in a TAB column, then
  192. Pushblanks
  193. MovAL,Tab
  194. CallPutChar
  195. PopAX
  196. ; and write it
  197. MovSw,0;Ind not blank
  198. TlWloop
  199. AL,CCR
  200. CallPutChar
  201. ; and LF
  202. CallPutChar
  203. JmpLoop
  204.  
  205. InsAany blanks that
  206. ; didn't line up on
  207. BlDL,column
  208. JbNone
  209. MovAL,' '
  210. CallPutChar
  211. DecDL;Decr insert count
  212. J; and continue
  213. AX;Get char back
  214. JmpCopy
  215.  
  216. Done:Ret
  217. GenTabEndp
  218. Page
  219. ;
  220. logicalrecord with TABs expanded
  221.  
  222. GeNear
  223. ;Targetrecord offset
  224. ;Quote indicator
  225.  
  226. ;Build up a logical record
  227. ; by looking for a CR or LF
  228. JeGet1; as end-of-record
  229. CmpAL,LF
  230. JeGet7
  231. CmpAL;Don't expand tabs
  232. JneGetwithin a
  233. ; quoted string
  234. AL,D_Quote
  235. JneGet3
  236. XorQsw,2
  237. AL,Tab;Is it TAB?
  238. JneGet5; no, pass it
  239. quotes?
  240. JnzGet5; yes, pass it as-is
  241. Reembedded tabs
  242. IncDI; with blanks
  243. TestDI,0007h
  244. JzGet1
  245. JmpGet4
  246.  
  247. Re;Build the record by
  248. IncDI; copying each character
  249. CmpD; or TABs expanded to blanks
  250. JaeGet6
  251. C;Is it EOF?
  252. JeGet6; yes, all done
  253. JmpGet1; no, continue
  254. CX,DI;Final record length
  255. Ret
  256.  
  257. Rec-1;Omit trailing blanks
  258. JneGet6
  259. DecDI
  260. JzGet6
  261. JmpGet7
  262.  
  263. GetRecEndp
  264. Page
  265. ;
  266. one char from record
  267.  
  268. GetNeaAL
  269. RIlebuffer?
  270. JsReablock
  271. Mo; yes, get offset in buf
  272. Lodsb
  273. Mfor next one
  274. Ret
  275.  
  276. RCX
  277. MovBblock of data
  278. MovC; into Input (segment) buffer
  279. MovDX,In_Ptr
  280. MovIptr,DX
  281. MovAH,3Fh
  282. Int21h
  283. PopCX
  284. Mo; and length
  285. JcRead3
  286. OrAX,AX;Anything read?
  287. ; yes, pick it up
  288. M; no, return EOF
  289. Ret
  290.  
  291. ;Say I/O ERROR
  292. JmpError
  293. GetCharEndp
  294. Page
  295. ;
  296. ;Block output records
  297.  
  298. PutNear;Write from AL
  299. PushCX
  300. Min buffer
  301. Stosb
  302. Mo;New buffer ptr
  303. IncOlen
  304. MovCX,Buflen
  305. Cm;Full block?
  306. J; yes, write it
  307. WrCX
  308. Ret
  309.  
  310. FlCX;Write data left over
  311. Mo;Any left in output?
  312. OrCX,CX
  313. JnzWrite3
  314. JmpWrite1
  315.  
  316. WriAX
  317. PushBP
  318. PushBX
  319. PushDX
  320. MovBX;Get file handle
  321. ;Save size requested
  322. MovDX,Out_Ptr
  323. MovOptr,DX
  324. M;Write the block
  325. Int21h
  326. ;Write OK?
  327. ;Wrote all data?
  328. MovOlen,BP
  329. ; yes, good
  330. W; no, say I/O error
  331. JmpError
  332.  
  333. WrDX
  334. PopBX
  335. PopBP
  336. PopAX
  337. PopCX
  338. Ret
  339. PutCharEndp
  340. Page
  341.  
  342. ;Open input file
  343.  
  344. OpNear
  345. MovDX,Offset Input
  346. Mov;For input
  347. Int21h
  348. JncOpeni
  349. MovDX,Offset Msg1
  350. JmpOpenErr
  351.  
  352. OIHandle,AX
  353. Ret
  354. OpenInEndp
  355.  
  356. ;Open output file
  357.  
  358. OpeNear
  359. MovDX,Offset Output
  360. ;Normalfile attribute
  361. a file
  362. Int21h
  363. JncOpeno
  364. M;Oops, can't open output
  365. JmpOpenErr
  366.  
  367. OOHandle,AX
  368. Ret
  369. OpenOutEndp
  370.  
  371. ;Determine why OPEN failed
  372.  
  373. OpeAL,reason code
  374. JbOpene
  375. CmpAL,5
  376. JaOpene
  377. ;Get offset to reason
  378. ; text failure
  379. MovCL,4
  380. ShlBX,CL
  381. Ca;Say OPEN FAILED
  382. MovDX,Offset NewLine
  383. CallPrintS
  384. LeaDX,Code2-32[BX]
  385. OError
  386.  
  387. ;Close input/output
  388.  
  389. CNear;Close files
  390. MovBX; output
  391. MovAH,3Eh
  392. Int21h
  393.  
  394. MovBX; input
  395. MovAH,3Eh
  396. Int21h
  397. Ret
  398. CloseEndp
  399. Page
  400. ;
  401. ;Get file names from command line
  402.  
  403. GetNear;Get file name(s)
  404. M;Point to command line
  405. ;The PSP may contain one or two
  406. OPtr; filenames separated by blanks
  407. JnzGetF0
  408. GeD;None, display usage message
  409. JmpError
  410.  
  411. ;Targetis infile for
  412. Incoperand
  413.  
  414. Get;Copy command line to file names
  415. C; by skipping leading blanks
  416. a CR isfound
  417. LoopeGetF1
  418. Jblank
  419.  
  420. GeAL,CR;Is it CR, end of line?
  421. JeGetFname
  422. C;Or option string?
  423. JeGetF1c
  424. blank?
  425. JeGetF2
  426. Stosb
  427. Lodsb
  428. LoopGetF1a
  429. JmpGetF5
  430.  
  431. GeA;Terminate fname operand
  432. Stosw
  433. Lodsb;Get option letter
  434. option for detabbing
  435. JeGetF1d
  436. CmpAL,'d'
  437. JneGetF3
  438. GeDetab,Stopper
  439. GetF3:
  440. JmpGetF6
  441.  
  442. GA;Terminate fname operand
  443. Stosw
  444. LeaDI,fname
  445. GetF2a:Lodsb
  446. C;Skip intervening blanks
  447. JneGetF2b
  448. LoopeGetF2a
  449. J;If no operand
  450.  
  451. GeAL,CR;Is it CR, end of line?
  452. JeGetF5; yes, end of name
  453. C;Or option string?
  454. ; yes, copy it
  455. C;Or ending blank?
  456. JeGetF2c
  457. Stosb;Copy second operand
  458. MovNewPtr,DI
  459. GetF2c:Lodsb
  460. LoopGetF2b
  461.  
  462. sign
  463. Stosw
  464.  
  465. GetF6:
  466. ;Any input name?
  467. ; yes, try output name
  468. J; no, display usage
  469.  
  470. GetF8:
  471. ;Find first matching file
  472. Ge;Any output name?
  473. ; yes, further check name
  474. CmpInp;Make sure don't over-write
  475. JeGetFo; the input file
  476. JmpGetUse
  477.  
  478. ;If just a drive is given
  479. ; for the output
  480. MovDI;Skip over drive
  481. MovNewptr,DI
  482. JmpSho; and copy as outfile name
  483.  
  484. GWord P;Drive and path?
  485. JeGetFs; yes, append infile name
  486. CmpBypath?
  487. Jn; no, outfile is a filename
  488.  
  489. Gpath delimiter
  490. MovAL,'\'
  491. Stosb
  492. MovNewPtr,DI
  493. GCX,7filename
  494. Movthe outfile spec
  495. MovSI,FilePtr
  496. RepMovsb
  497. GetFend:Ret
  498. GetFileEndp
  499. Page
  500. ;
  501. ;Find first matching file, just cuz I'm lazy
  502.  
  503. Near;Find first matching file
  504. ;Set data xfer area
  505. MovAH,1Ah
  506. Int21h
  507. Mo;Input path\filename.ext
  508. ;Searchfor first normal file
  509. MovAH,4Eh
  510. Int21h
  511. JncFind1
  512. ;Say NOMATCHING FILE
  513. JmpError
  514.  
  515. AL,Afor return
  516. ; if none found
  517. MovDI,Offset Input
  518. CmpByt;If drive was supplied
  519. ; leaveit in file name
  520. AddDI,2
  521. FB;If path was supplied
  522. J; try to leave it in Input name
  523. MovSI,Offset Input+75
  524. Std
  525. MovCX,76
  526. Find3:Lodsb
  527. C;Find the last separator
  528. JeFinspec
  529. LoopFind3
  530. MovSI,DI
  531.  
  532. FDI,SI
  533. AddDI,2
  534. FiFi;Save addr of filename part
  535. FCX,13;Copy found name to Input name
  536. MovDI,FilePtr
  537. Cld
  538. Mpath name
  539. Find7:Lodsb
  540. Stosb
  541. CmpAL,0;Don't want crud in message
  542. LoopneFind7
  543. FAL,Stopper
  544. Stosb
  545. ;Set good return code
  546. Ret
  547.  
  548. AH,4Fh;Get next matching file
  549. Int21h
  550. OrAL,AL; any more?
  551. J; no, just return
  552.  
  553. ;Re-initialize
  554. MovSw,0
  555. M;Reset buffer counts
  556. MovIlen,0
  557. MovAX;Reset buffer ptrs
  558. MovOptr,AX
  559. MovAX,In_Ptr
  560. MovIptr,AX
  561. Mov;Was output name supplied?
  562. CmpAX,Newptr
  563. Jne     Next1
  564. Mov;Reset output file name
  565. Next1:
  566. MovCX,8;Clear message prefix
  567. MovSI,Offset Spaces
  568. MovDI,Offset InformD
  569. RepMovsb
  570. MovCooking,CR
  571. MovCooking+1,LF
  572.  
  573. MovD;Copy input name as output name
  574. MovCX,13
  575. MovSI,Offset DTA+30
  576. Next7:Lodsb
  577. Stosb
  578. CmpAL,0;Don't want crud in message
  579. LoopneNext7
  580. MovAL,Stopper
  581. Stosb
  582. ; yes, name
  583. Nexted:Ret
  584. FindEndp
  585.  
  586. Page
  587. ;
  588. "cooking" message
  589.  
  590. InNear
  591. MovDX,Offset Cooking
  592. CmpDetab,0
  593. JeInform1
  594. MovDX,Offset InformD
  595. InfoPrintS
  596. MovDX,Offset Input
  597. CallPrintS
  598. MovDX,Offset Mark
  599. CallPrintS
  600. MovDX,Offset Output
  601. CallPrintS
  602. Ret
  603. InformEndp
  604.  
  605. ChNear
  606. MovAH,30h
  607. Int2or later
  608. CmpAL,2
  609. JaeChk9
  610. MovDX,Offset Sorry
  611. JmpError
  612. Chk9:Ret
  613. ChkVerEndp
  614.  
  615. PrNear;Print string like Int 21h (9)
  616. PushBX;DX points to string
  617. PushSI
  618. MovSI,DX
  619. PS1:Lodsb
  620. Cmpa hex FF
  621. JePSsign
  622. CmpAL,zeros
  623. JePS1
  624. MovDL,AL
  625. MovAH,2;Display to standard device
  626. Int21h
  627. JmpPS1
  628.  
  629. PS9:PopSI
  630. PopBX
  631. Ret
  632. PrintSEndp
  633.  
  634. Page
  635. ;
  636. ;Allocate up to 32K per buffer by modifying memory
  637. program.
  638. more complicated than using data segments
  639. buffersof allowing
  640. ;for variable buffer sizes depending upon the amount
  641. also allows DS and ES to remain
  642. Besides, the COM version is under 2K bytes.
  643.  
  644. ANear;Get I/O buffers
  645. MovCX;Program size in paragraphs
  646. MoPaddress
  647. ;My starting seg address
  648. ;Paragrthis COM program
  649. ; less code size
  650. ;Next addr
  651.  
  652. CmpBX;Can only use 64k
  653. JbeAlloc0
  654. MovBX,Maxcore
  655. AlI;Seg addr for input buffer
  656. Cmprun?
  657. JbAlloc1
  658. ;Size less stack and PSP
  659. AlBX,buffer
  660. AddAX,BX
  661. MovOu;Seg addr for output buffer
  662.  
  663. MovAX,BX
  664. MovCL,4
  665. ;Convert to bytes
  666. MovBufLen,AX
  667. CmpAX;Have enough?
  668. ; nope,bye
  669.  
  670. ;Convert ptrs to offsets
  671. MovAX,In_Ptr
  672. SubAX,DX
  673. ShlAX,CL
  674. MovIn_Ptr,AX
  675. MovIptr,AX
  676.  
  677. MovAX,Out_Ptr
  678. SubAX,DX
  679. ShlAX,CL
  680. MovOut_Ptr,AX
  681. MovOptr,AX
  682. Ret
  683.  
  684. A;Not enough memory
  685. JmpError
  686.  
  687. AllocEndp
  688.  
  689. TabsEndp
  690.  
  691. ;Cseg alength
  692. Ma(36size
  693. Mi32
  694.  
  695. CsegEnds
  696. EndTabs
  697.